
function checkforblanks()
	{
	for (var i = 0; i < arguments.length; i += 2)
		{
		if (!arguments[i])
			{
			alert("Please enter " + arguments[i+1] + ".");
			return false;
			}
		}
	return true;
	}


function validateEmail(FormName){

var strValue = FormName.Email.value;

var objRegExp  = /^([a-zA-Z0-9_\.\-\&])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
 
  if(!objRegExp.test(strValue))
{
	alert("E-mail address contain invalid format"); 

		return false;
}
 else
 {
	return true;
}
}

function validatePhone(FormName) {

var strValue = FormName.phonenumber.value;
  var objRegExp  = /^[1-9]\d{2}\s?\d{3}\d{4}$/;
  var obj2RegExp  = /^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/;

  if(objRegExp.test(strValue) || obj2RegExp.test(strValue))
  {  	return true;
  }
else{
	alert("Phone number is in valid must in the form of 999 9999999 or (999) 999-9999"); 

	return false;
	}
}

function validatePassword(FormName){

	if(FormName.password.value == "")
	{
		alert("Password field cannot be empty");
		return false;
	}
	if(FormName.password.value == FormName.conf_password.value)
	{	return true;	}
	else 
	{
		alert("Password and Confirm Password fields do not match, Please check it again."); 
		return false;
	}
	
}

function isEmpty(FormName)
{
		var isFull = checkforblanks(FormName.last_name.value, "Last Name", FormName.first_name.value, "First Name",
					FormName.username.value, "User Name");
	if(isFull){
	return true;
	}
	else{
	return false;
	}
}


function validate(FormName){
	if(validatePassword(FormName) && validatePhone(FormName) && validateEmail(FormName) && isEmpty(FormName))
	{
		
		return true;	

	}
	else{
	
	return false;
	}
}

function validatemod(FormName)
{
	
	if(/*validatePhone(FormName) && */validateEmail(FormName) && validatePassword(FormName))
	{
		if(isEmpty(FormName))
		{
			return true;	
		}
		else{
		return false;
		}
	}
	else{
		return false;
	}

}



function checkdepart(FormName)
{
	if(!FormName.department.value)
	{
		alert("Department Can Not Be Empty");
		return false;
	}
	else
	{
		return true;
	}
}

function checkcategory(FormName)
{
	if(!FormName.category.value)
	{	
		alert("Category Can Not Be Empty");
		return false;
	}
	else{
		return true;
	}
}

function checkforempty($var)
{
	if(!$var)
	{
		alert("Error, Field Can Not Be Empty");
		return false;
	}
	else
	{
		return true;
	}
}

